<?php
require_once(dirname(dirname(__FILE__)).'/init.php');
require_once(ROOT_PATH.'service/wxjssdk/jssdk.php');

/**
* wxjsApi 微信jssdk 
* shouxue
* 2017/10/26 
*/
class WxjsApi extends Base
{
	
	//初始化
	function __construct($Ioc)
	{
		//载入可访问区域
		$this->Method = array('Wxshare','share_info');
		$this->Ioc 	  = $Ioc;
			
	}


    /**
     * Description: 主体服务
     * User: shouxue
     * Date: 2017/10/27
     */
    public function main($mode)
    {

        if (!$this->isMethod($mode)) {
            $this->Ioc->Response->Json(212, '请求服务不存在','',$this ->out_mode);
        }

        $data = array();
        //接入Api
        switch ($mode)
        {
            case "Wxshare":
                    $data  = $this ->Wxshare();
                 break;
             case "share_info":
                    $data  = $this ->share_info();
                 break;
            default:
                  
        }

        if (!$data && $data['code'] != 200) {
            $this->Ioc->Response->Json($data['code'], $data['msg'],'',$this ->out_mode);
        }

        $this->Ioc->Response->Json(200, '成功', $data,$this ->out_mode);
    }


   /**
     * Description: 微信分享服务
     * User: shouxue
     * Date: 2017/10/27
     */
    public function wxshare()
    {

    	$url  = isset($_REQUEST['url']) ? trim($_REQUEST['url'] ) : '';
    	if(!$url){
    		 $this->Ioc->Response->Json(213, '来源不能为空','',$this ->out_mode);
    	}

        $jssdk  = new JSSDK(AppId, AppSecret);
		$data   = $jssdk->GetSignPackage($url);

		unset($data['rawString']);

        return  $this->Ioc->Response->Min(200, '成功', $data,$this ->out_mode);
    }


    /**
     * Description: 微信分享信息
     * User: shouxue
     * Date: 2017/10/27
     */
    public function share_info()
    {

    }



}

//检测来源
$stat = is_origin();
if(!$stat){
   //$Ioc->Response->Json(224,'无接口访问权限','','json');
}

$mode    = trim($_REQUEST['mode']);
$WxjsApi = new WxjsApi($Ioc);
$WxjsApi ->main($mode); 



